﻿namespace EMall.Domain
{
    public abstract class Repository<TAggregateRoot, TKey> : IRepository<TAggregateRoot, TKey>
     where TAggregateRoot : class, IAggregateRoot<TKey>
    {
        public virtual void Add(TAggregateRoot entity) => AddAsync(entity).Wait();
        public abstract Task AddAsync(TAggregateRoot entity);
        public virtual void Remove(TAggregateRoot entity) => RemoveAsync(entity).Wait();
        public abstract Task RemoveAsync(TAggregateRoot entity);
        public abstract IQueryable<TAggregateRoot> GetQueryable();
        public virtual int Count() => CountAsync().Result;
        public abstract Task<int> CountAsync();
        public virtual TAggregateRoot Get(TKey id) => GetAsync(id).Result;
        public abstract Task<TAggregateRoot> GetAsync(TKey id);
    }
}